package com.yf.dmp.service;

import com.alibaba.fastjson.JSON;
import com.yf.dmp.bean.User;
import com.yf.dmp.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;

import java.util.HashMap;

@Service
@Transactional
public class LoginService {
    @Autowired
    private UserDao uDao;

    public String Login(User user){
        String flag = "error";
        User us = uDao.getUserLogin(user.getUsername(),DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
        HashMap<String, Object> res = new HashMap<>();
        if(us != null){
            flag = "ok";
        }
        res.put("flag",flag);
        res.put("user",us);
        String jsonstr = JSON.toJSONString(res);
        return  jsonstr;
    }
}
